<?php
//session_start();
//include('function/initialize.php');
include('function/connection.php');
if(isset($_REQUEST['salenumber']))
{
	
	//get Rate of money
	$sql_rate="SELECT money FROM  tbl_currency ";
	$result_rate=mysql_query($sql_rate);
	$row_rate=mysql_fetch_assoc($result_rate);
	$rate_money=$row_rate['money'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Sales Print</title>
<style type="text/css" media="print">
.hide{display:none}
</style>
<script type="text/javascript">
function printpage() {
document.getElementById('printButton').style.visibility="hidden";
window.print();
document.getElementById('printButton').style.visibility="visible";  
}
</script>
<style type="text/css">
<!--
.style1 {font-size: 10px}
-->
</style>
</head>

<body style="font-size:13px;">
<input name="print" type="button" value="Print" id="printButton" onClick="printpage()">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" valign="top">
	
	<table width="595"  cellspacing="0" cellpadding="0" id="bordertable"  border="1">
      <tr>
        <td align="left"><h3><img src="images/logo_marly.png" width="130"  height="40" />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Sales Receipt</h3> 
        </strong>
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="67%" align="left" valign="top">&nbsp;&nbsp;&nbsp;Date: 
			  <?php
				  $salenumber=$_REQUEST['salenumber'];
				   //$salenumber="SA95";
				  $sql="SELECT * FROM tbl_sales WHERE sale_id='$salenumber'";
				  $result=mysql_query($sql);
				  $row=mysql_fetch_assoc($result);
				  $saleDate=$row['sale_date'];
				  $customerName=$row['cus_name'];
				  
				  $mysqldate=$saleDate;
				  $phpdate = strtotime( $mysqldate );
				  $phpdate = date("d/m/Y",$phpdate);
				  echo $phpdate;
			  ?> <br />
                <br />
                <strong><br />
                &nbsp;&nbsp;&nbsp;Receipt No: <?php echo $salenumber;
				
				 ?> </strong><br /></td>
              <td width="35%"><strong>Hay Soeung Company</strong><br />
Russian Blvd Sang Kat Toek Thla, <br />Khan Sen Sok, Phnom Penh, Cambodia<br />
Email: hay_soeng@yahoo.com<br/>
Website:&nbsp;www.haysoeungautomobile.com<br />
Tel: <span large;\>+85512 544498</span><br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;+85512 287899<br/>
			
		  </td>
            </tr>
          </table></td>
      </tr>
      <tr>
        <td height="90" align="left" valign="top"><br />
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="5%" align="left" valign="top"><strong>&nbsp;&nbsp;TO:</strong></td>
              <td width="95%" align="left" valign="top"><br />
              <?php 
			  	echo "Name: ".$customerName;
				$sql="SELECT * FROM tbl_customers WHERE cus_name='$customerName' ";
				$result=mysql_query($sql);
				$row=mysql_fetch_assoc($result);
				?>
				<br />
				<?php
				echo "Contact1: ".$row['cus_contact1']."<br>";
				echo "Contact2: ".$row['cus_contact2']."<br>";
					
				
				?></td>
            </tr>
          </table></td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="12%" align="center" bgcolor="#CCCCCC"><strong>No.</strong></td>
            <td width="22%" bgcolor="#CCCCCC"><strong>Stock</strong></td>
            <td width="18%" bgcolor="#CCCCCC"><strong>Quantity</strong></td>
            <td width="19%" bgcolor="#CCCCCC"><strong>Rate</strong></td>
            <td width="11%" bgcolor="#CCCCCC">&nbsp;</td>
            <td width="18%" bgcolor="#CCCCCC"><strong>Total</strong></td>
          </tr>
		  
          <tr>
            <td align="center">&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
		  <?php
		  $i=1;
		  $sql="SELECT * FROM tbl_sales where sale_id='$salenumber'";
		  $result=mysql_query($sql);
while ($row = mysql_fetch_object($result)) {
	$qty=$row->qty;
	$selling_price=$row->selling_price;
?>
          <tr>
            <td align="center"><?php echo $i."."; ?></td>
            <td><?php echo $row->pd_name; ?></td>
            <td><?php echo $qty; ?></td>
            <td><?php echo $selling_price."$"; ?></td>
            <td>&nbsp;</td>
            <td><?php echo $row->total."$"; ?></td>
          </tr>
		  
		  <?php
	$i++;	
	$subtotal=$row->amount; 
	//$subtotal= $qty * $selling_price;   
	$payment=$row->paid;
	$balance=$row->balance;
	$date=$row->sale_last_update;	    
}//end while
		  ?>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td></td>
          </tr>
        </table></td>
      </tr>
	  <tr>
	  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="82%" align="right" bgcolor="#CCCCCC"><strong>SubTotal:&nbsp;&nbsp;</strong></td>
          <td width="18%" bgcolor="#CCCCCC"><?php echo @$subtotal."$"; ?>&nbsp;</td>
        </tr>
        <tr>
          <td width="82%" align="right" bgcolor="#CCCCCC"><strong>Riel:&nbsp;&nbsp;</strong></td>
          <td width="18%" bgcolor="#CCCCCC">
		  <?php   
				@$number=$subtotal*$rate_money;
				echo number_format($number, 2, '.', ',') ."R"; 
		  ?>
          &nbsp;</td>
        </tr>
      </table>	  </td>
	  </tr>
      <tr>
        <td align="right"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="40%" align="left" valign="top"><br />
              <strong>&nbsp;&nbsp;Paid Amount :&nbsp;&nbsp;<?php echo @$payment."$"; ?><br />
              <strong>&nbsp;&nbsp;Paid Riel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;<?php @$number=$payment*$rate_money;echo number_format($number, 2, '.', ',') ."R"; ?><br />
              &nbsp;&nbsp;Left Money &nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;<?php echo @$_REQUEST['leftMoney'].".00$"; ?><br />
              &nbsp;&nbsp;Balance &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;:&nbsp;&nbsp;<?php echo @$balance."$"; ?><br />
              &nbsp;&nbsp;Due Date&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;: 
			  <?php 
			  	if(@$balance > 0) {
					  $mysqldate=$date;
		
					  $phpdate = strtotime( $mysqldate );
			
					  $phpdate = date("d/m/Y",$phpdate);
					  echo $phpdate;
				  }
			  ?> <br />
              </strong> </td>
            <td width="67%" align="right"><br />
              <br />
              <br />
              Signature&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td align="center" bgcolor="#CCCCCC">Thank you for Business with Us </td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
<?php
}else{
	echo "Please input invoice number....!";}
?>